from __future__ import division
import sys
import math


memoi_comb = {}
def get_combinations(n, k):
  combinations = memoi_comb.get((n, k)) 
  if combinations:
    return combinations
  if k == 0 or k == n:
    combinations = 1
  else:
    combinations = (get_combinations(n-1, k) + get_combinations(n-1, k-1))
  memoi_comb[(n, k)] = combinations
  return combinations


#fin = open("virtical_sticks.py.txt")
def readline():
    #return fin.readline()
    return sys.stdin.readline()

def expected_length_for_number_in_pos(pos, index, arr):
    smaller = 0
    bigger = 0
    total_lengh = 0
    current = arr[index]

    for i in range(len(arr)):
        if i != index:
            if arr[i] < current: 
                smaller = smaller + 1
            else:
                bigger = bigger + 1
    #print((smaller, bigger))
    for max_len in range(1, pos + 2):
        if max_len - 1 > smaller:
            break;
        if bigger == 0:
            if max_len == pos + 1:
                total_lengh = max_len * math.factorial(len(arr) - 1) + total_lengh
                break
            else:
                continue

        if(max_len == pos + 1):
            smaller_in_the_middle_count = max_len - 1;
            others_count = len(arr) - smaller_in_the_middle_count - 1
            combinations = get_combinations(smaller, smaller_in_the_middle_count) * math.factorial(smaller_in_the_middle_count) * math.factorial(others_count)
            #print(("max_len - 1",max_len - 1))
            #print(("combinations",  combinations))
            total_lengh = total_lengh + max_len * combinations
            #print(("total_lengh", total_lengh))
        else:
            smaller_in_the_middle_count = max_len - 1;
            others_count = len(arr) - smaller_in_the_middle_count - 2
            combinations = get_combinations(smaller, smaller_in_the_middle_count) * math.factorial(smaller_in_the_middle_count) * bigger * math.factorial(others_count)
            #print(("max_len - 1",max_len - 1))
            #print(("combinations",  combinations))
            total_lengh = total_lengh + max_len * combinations
            #print(("total_lengh", total_lengh))

    return total_lengh / math.factorial(len(arr) - 1)


def main():
    num_tests = int(readline())
    for _ in range(num_tests):
        num_count = int(readline().strip())
        numbers = list(map(int, readline().split(' ')))
        sum_sofar = 0;
        for i in range(num_count):
            sum_for_pos_sofar = 0
            for j in range(num_count):
                sum_for_pos_sofar = sum_for_pos_sofar + expected_length_for_number_in_pos(i, j, numbers)
            sum_sofar = sum_for_pos_sofar / num_count + sum_sofar
        print("%0.2f" % sum_sofar)


def f_main():
    arr = [3,3,3]
    print(expected_length_for_number_in_pos(1,0,arr))



if __name__ == '__main__':
    main()
